package com.yx.elastic.elasticcm.orm;

/**
 * Created by chenzp on 18-8-1.
 */
public enum ElasORMExceptionCode {

    MORE_ANNOTATION("存在多个注解",2301),
    NOT_METHOD("不存在set，get方法",2302),
    NOT_DOC_INDEX("实体类EDoc注解index值不能为空",2303),
    NOT_DOC_TYPE("实体类EDoc注解type值不能为空",2304),
    NOT_DOC("不存在edoc",2305),
    NOT_ID("不存在ID",2306);

    private String message;

    private int code;

    ElasORMExceptionCode(String message, int code) {
        this.message = message;
        this.code = code;
    }

    /**
     * 根据状态code获取枚举
     * @return
     */
    public static ElasORMExceptionCode getByCode(int code) {
        for (ElasORMExceptionCode status : ElasORMExceptionCode.values()) {
            if (status.getCode()== code) {
                return status;
            }
        }
        return null;
    }

    /**
     * 根据状态code获取枚举值
     * @return
     */
    public static String getNameByCode(int code) {
        for (ElasORMExceptionCode status : ElasORMExceptionCode.values()) {
            if (status.getCode() == code) {
                return status.message;
            }
        }
        return null;
    }

    public String getMessage() {
        return message;
    }

    public int getCode() {
        return code;
    }
}
